package com.buercorp.wangyu.core1.ch9.priorityQueue;

import java.util.*;
import java.time.*;

/**
 * This program demonstrates the use of a priority queue.
 * 优先级队列的使用
 *
 * @author Cay Horstmann
 * @version 1.02 2015-06-20
 */
public class PriorityQueueTest {
    public static void main(String[] args) {
        var pq = new PriorityQueue<LocalDate>();
        LocalDate now = LocalDate.now();
        System.out.println("当前时间日期是" + now);
        // 指定日期
        pq.add(LocalDate.of(1906, 12, 9)); // G. Hopper
        pq.add(LocalDate.of(1815, 11, 10)); // A. Lovelace
        pq.add(LocalDate.of(1903, 12, 3)); // J. von Neumann
        pq.add(LocalDate.of(1910, 6, 22)); // K. Zuse
        pq.add(LocalDate.of(2024, 1, 22)); // K. Zuse

        System.out.println("Iterating over elements . . .");
        for (LocalDate date : pq)
            System.out.println(date);
      /*
      * 1815-12-10
        1906-12-09
        1903-12-03
        1910-06-22
      * */
        System.out.println("Removing elements . . .");
        while (!pq.isEmpty())
            System.out.println("删除的元素：" + pq.remove());
        /*
        * 1815-12-10
          1903-12-03
          1906-12-09
          1910-06-22
        * */
        System.out.println("删除后" + pq);
    }
}
